import request from './index.js'

// 订单相关接口
export const orderApi = {
    // 创建订单
    create: (data) => {
        console.log('调用订单创建API，数据:', JSON.stringify(data));
        return request({
            url: '/order/create',
            method: 'post',
            data
        }).then(res => {
            console.log('订单创建API响应:', JSON.stringify(res));
            return res;
        }).catch(err => {
            console.error('订单创建API错误:', err);
            throw err;
        });
    },
    // 获取订单列表
    getList: (params) => {
        return request({
            url: '/order/list',
            method: 'get',
            params
        })
    },
    // 获取订单详情
    getDetail: (id) => {
        return request({
            url: `/order/${id}`,
            method: 'get'
        })
    },
    // 取消订单
    cancel: (id, reason) => {
        return request({
            url: `/order/${id}/cancel`,
            method: 'post',
            data: { reason }
        })
    },
    // 确认收货
    confirm: (id) => {
        return request({
            url: `/order/${id}/confirm`,
            method: 'post'
        })
    },
    // 删除订单
    delete: (id) => {
        return request({
            url: `/order/${id}`,
            method: 'delete'
        })
    },
    // 获取订单统计
    getCounts: () => {
        return request({
            url: '/order/counts',
            method: 'get'
        })
    },
    // 支付订单
    pay: (id, paymentMethod) => {
        return request({
            url: `/order/${id}/pay`,
            method: 'post',
            data: { paymentMethod }
        })
    }
} 